using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Afrs.Draco.Prms.Client.Proxy;
using Afrs.Prms.DataObject;

namespace 
{
  /// <summary>
  /// Requests Test Class
  /// </summary>
  [TestClass]
  public class TestRequests
  {
    #region Class Variables
    private CdoPrms<DORequests>		m_Requests;
    private CdoPrmsList<DORequests>	m_AllRequests;
    #endregion

    #region Class Constructors & Destructors
    /// <summary>
    /// Constructs the test
    /// </summary>
    public TestRequests()
    {
      // Create the data objects
      this.m_Requests	= new CdoPrms<DORequests>();
      this.m_AllRequests	= new CdoPrmsList<DORequests>();
    }
    #endregion

    #region Class Methods
    /// <summary>
    /// Retrieves all Requests data objects
    /// </summary>
    [TestMethod]
    public void RequestsRetrieveAll()
    {
      // Set up the data object for list retrieval
      this.m_AllRequests.DataObject = new DORequests();
      this.m_AllRequests.ListAction = AfrsDOListAction.Retrieve;

      // Perform the action and determine the success
      if (!this.m_AllRequests.PerformAction())
      {
        // Assert the errors
        if (this.m_AllRequests.Errors.Count > 0) { Assert.Fail(this.m_AllRequests.Errors[0].Message); }
        else { Assert.Fail("Unknown error occurred"); }
      }

      // Return to calling method
      return;
    }

    /// <summary>
    /// Create a new Requests
    /// </summary>
    [TestMethod]
    public void RequestsCreate()
    {
      // Set up the data object for creation
      this.m_Requests.DataObject.CreatedByUserId = 12.3F;
      this.m_Requests.DataObject.RequestDate = DateTime.Now;
      this.m_Requests.DataObject.RequestStatus = "Test RequestStatus";
      this.m_Requests.DataObject.Comments = "Test Comments";
      this.m_Requests.DataObject.ApprovedByUserId = 12.3F;
      this.m_Requests.DataObject.ApprovedDate = DateTime.Now;
      this.m_Requests.DataObject.OpenByUserId = 12.3F;
      this.m_Requests.DataObject.OpenDate = DateTime.Now;
      this.m_Requests.DataObject.ClosedByUserId = 12.3F;
      this.m_Requests.DataObject.ClosedDate = DateTime.Now;
      this.m_Requests.DataObject.DepartmentName = "Test DepartmentName";
      this.m_Requests.DataObject.DivisionName = "Test DivisionName";
      this.m_Requests.DataObject.Action = AfrsDataObjectAction.Create;

      // Perform the action and determine the success
      if (!this.m_Requests.PerformAction())
      {
        // Assert the errors
        if (this.m_Requests.Errors.Count > 0) { Assert.Fail(this.m_Requests.Errors[0].Message); }
        else { Assert.Fail("Unknown error occurred"); }
      }

      // Return to calling method
      return;
    }

    /// <summary>
    /// Retrieves a specific Requests
    /// </summary>
    [TestMethod]
    public void RequestsRetrieve()
    {
      // Determine whether the data object needs to be specified
      if (this.m_Requests.DataObject.Id == 0)
      {
        // Specify the data object to retrieve
        this.m_Requests.DataObject.RequestId = 10;
      }

      // Set up the data object action for retrieval
      this.m_Requests.DataObject.Action = AfrsDataObjectAction.Retrieve;

      // Perform the action and determine the success
      if (!this.m_Requests.PerformAction())
      {
        // Assert the errors
        if (this.m_Requests.Errors.Count > 0) { Assert.Fail(this.m_Requests.Errors[0].Message); }
        else { Assert.Fail("Unknown error occurred"); }
      }

      // Return to calling method
      return;
    }
    #endregion
  }
}
